package com.yunfei.yikao.web.controlller;

import com.google.code.kaptcha.Constants;
import com.yunfei.yikao.web.dataobject.ZhangyunfeiYikao;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;

/**
 * @Author: yunfei
 * @Date: 16:33
 */
@Controller
public class LoginControl {
    @RequestMapping(path = "login")
    public ModelAndView login(ZhangyunfeiYikao yikao, @RequestParam("captcha") String captcha, HttpSession session){
        if (!captcha.equals(session.getAttribute(Constants.KAPTCHA_SESSION_KEY))) {
            return new ModelAndView("redirect:login.html");
        }
        if (yikao.getName().equals("admin@admin.com") && yikao.getPassword().equals("yunfei123")) {
            session.setAttribute("yikao",yikao);
            return new ModelAndView("redirect:index.html");
        }
        return new ModelAndView("redirect:login.html");
    }


}
